<?php
declare(strict_types=1);

namespace app\model;

use Predis\Client;

class MyRedis
{
    private static Client $client;


    const EXPIRE_TIME = 2592000;// redis 过期时间 30 天

    /**
     * @return Client
     */
    public static function getRedisInstance(): Client
    {
        return self::generateRedisInstance();
    }// getRedisInstance() end

    /**
     * @return Client
     */
    public static function generateRedisInstance(): Client
    {
        if (empty(self::$client) === false && self::$client instanceof Client) return self::$client;

        self::$client = new Client([
            'scheme' => 'tcp',
            'host'   => config('database.redis.host'),
            'port'   => config('database.redis.port'),
        ], ['prefix' => config("database.redis.prefix")]);
        return self::$client;
    }// generateRedisInstance() end
}